package com.situ.crm.interceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.HandlerInterceptor;

import com.situ.crm.common.Constants;

//登录拦截器
public class LoginInterceptor implements HandlerInterceptor {

	@Override
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
		// 创建变量保存是否已经登录
		boolean isLogin = false;
		isLogin = request.getSession().getAttribute(Constants.SESSION_CURRENT_KEY) != null;
		
		if(!isLogin) {
			response.sendRedirect("/login");
		}
		
		return isLogin;
	}

}
